package com.github.fujianlian.klinechart.draw.main;

import android.graphics.Canvas;
import android.graphics.Paint;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.fujianlian.klinechart.BaseKLineChartView;
import com.github.fujianlian.klinechart.draw.Status;
import com.github.fujianlian.klinechart.entity.h.ICandle;
import com.github.fujianlian.klinechart.entity.h.IKLine;

/**
 * reate by tao on{DATE}
 */
public class ENEDraw extends BaseMainDraw {

    private Paint ma5Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint ma10Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint ma30Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint ma60Paint = new Paint(Paint.ANTI_ALIAS_FLAG);


    public ENEDraw(BaseKLineChartView view) {
        super(view,Status.ENE.getId());
    }

 

    @Override
    public void setLine(boolean line) {
        isLine = line;
    }

    @Override
    public void drawText(@NonNull Canvas canvas, @NonNull BaseKLineChartView view, int position, float x, float y) {
        if (!isStatus(Status.ENE)) return;

        ICandle point = (IKLine) view.getItem(position);
        if (point.getENE() == 0) return;
        if (isLine) {
            String text = "ENE:" + view.formatValue(point.getENE()) + "  ";
            canvas.drawText(text, x, y, ma10Paint);

        } else {
      
                String text = "ENE:" + view.formatValue(point.getENE()) + "  ";
                canvas.drawText(text, x, y, ma10Paint);
                x += ma10Paint.measureText(text);
                text = "UP:" + view.formatValue(point.getENE_UPPER()) + "  ";
                canvas.drawText(text, x, y, ma10Paint);
                x += ma10Paint.measureText(text);
                text = "LO:" + view.formatValue(point.getENE_LOWER());
                canvas.drawText(text, x, y, ma10Paint);
    
            
        }
    }

    @Override
    public void drawTranslated(@Nullable ICandle lastPoint, @NonNull ICandle curPoint, float lastX, float curX, @NonNull Canvas canvas, @NonNull BaseKLineChartView view, int position) {
        if (!isStatus(Status.ENE)) return;

        if (isLine()) {
            if (lastPoint.getENE_UPPER() != 0) {
                view.drawMainLine(canvas, ma5Paint, lastX, lastPoint.getENE_UPPER(), curX, curPoint.getENE_UPPER());
            }
            if (lastPoint.getENE_LOWER() != 0) {
                view.drawMainLine(canvas, ma10Paint, lastX, lastPoint.getENE_LOWER(), curX, curPoint.getENE_LOWER());
            }
            if (lastPoint.getENE() != 0) {
                view.drawMainLine(canvas, ma30Paint, lastX, lastPoint.getENE(), curX, curPoint.getENE());
            }
        } else {
            if (lastPoint.getENE_UPPER() != 0) {
                view.drawMainLine(canvas, ma5Paint, lastX, lastPoint.getENE_UPPER(), curX, curPoint.getENE_UPPER());
            }
            if (lastPoint.getENE_LOWER() != 0) {
                view.drawMainLine(canvas, ma10Paint, lastX, lastPoint.getENE_LOWER(), curX, curPoint.getENE_LOWER());
            }
            if (lastPoint.getENE() != 0) {
                view.drawMainLine(canvas, ma30Paint, lastX, lastPoint.getENE(), curX, curPoint.getENE());
            }
        }
    }

 
    public void setMa5Color(int color) {
        ma5Paint.setColor(color);
    }

 
    public void setMa10Color(int color) {
        ma10Paint.setColor(color);
    }

 
    public void setMa30Color(int color) {
        ma30Paint.setColor(color);
    }

    public void setStrokeWidth(float width) {
        ma5Paint.setStrokeWidth(width);
        ma10Paint.setStrokeWidth(width);
        ma30Paint.setStrokeWidth(width);
    }

    public void setTextSize(float textSize) {
        ma10Paint.setTextSize(textSize);
    }
}
